/*
 *------------------------------------------------------------------------------
 * @File      :    ei_mai_vdec_define.h
 * @Date      :    2021-4-8
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Media Interface for MADP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */

#ifndef __EI_VDEC_DEFINE_H__
#define __EI_VDEC_DEFINE_H__

#ifdef __cplusplus
#if __cplusplus
extern "C"
{
#endif
#endif

#include "ei_comm_vdec.h"
#include "ei_mai_comm_define.h"

/** max channel count of video decoder*/
#define EI_VDEC_MAX_CHN_NUM   8

//#define VDEC_CHN_REGISTER_CALLBACK_MAX_COUNT  1

#define EI_VDEC_LIMITLESS_FRAME_COUNT -1

#define VDECODE_GET_STREAM_THREAD_USLEEP_TIME  (10 * 1000)
#define VDECODE_GET_STREAM_THREAD_SLEECT_TIMEOUT_USEC  (10 * 1000)

#define EI_VDEC_MSG_BASE (0x2000)

#define EI_VDEC_MSG_ON_SEND_STREAM_DONE (EI_VDEC_MSG_BASE+1)

#define EI_VDEC_MSG_ON_DECODE_FRAME_DONE (EI_VDEC_MSG_BASE+2)

#define EI_VDEC_MSG_ON_DECODE_ERROR (EI_VDEC_MSG_BASE+3)

typedef enum eiVDEC_ERR_CODE_E
{
    EN_VDEC_DECODE_FAILED = 0x40,
    EN_VDEC_STREAM_BUF_FULL = 0x41,
    EN_VDEC_CREATE_FAILED = 0x42,
    EN_VDEC_NOT_INITED = 0x43,
    EN_VDEC_NOT_STARTED = 0x44,
    EN_VDEC_LOADSO_FAILED = 0x45,
    EN_VDEC_UNLOADSO_FAILED = 0x46,
    EN_VDEC_ALREADY_REGISTER = 0x47,
    EN_VDEC_NO_VBBLK = 0x48
}EI_VDEC_ERR_CODE_E;

#define EI_ERR_MAI_VDEC_HANDLE_ILLEGAL                EI_MADP_DEF_ERR(EI_ID_VDEC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_INVALID_CHNID)
#define EI_ERR_MAI_VDEC_NULL_PTR                       EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NULL_PTR)
#define EI_ERR_MAI_VDEC_ILLEGAL_PARAM               EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_ILLEGAL_PARAM)
#define EI_ERR_MAI_VDEC_DECODE_FAILED            EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_DECODE_FAILED)
#define EI_ERR_MAI_VDEC_NOT_PERM                      EI_MADP_DEF_ERR(EI_ID_VDEC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_NOT_PERM)
/*codec type not supported*/
#define EI_ERR_MAI_VDEC_NOTSUPPORT                EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_SUPPORT)
#define EI_ERR_MAI_VDEC_CREATE_FAILED             EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_CREATE_FAILED)
#define EI_ERR_MAI_VDEC_NOT_INITED                   EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_NOT_INITED)
#define EI_ERR_MAI_VDEC_NOT_STARTED               EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_NOT_STARTED)
#define EI_ERR_MAI_VDEC_NOMEM                         EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOMEM)
#define EI_ERR_MAI_VDEC_STREAM_BUF_FULL      EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_STREAM_BUF_FULL)
#define EI_ERR_MAI_VDEC_LOADSO_FAILED           EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_LOADSO_FAILED)
#define EI_ERR_MAI_VDEC_UNLOADSO_FAILED     EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_UNLOADSO_FAILED)
#define EI_ERR_MAI_VDEC_ALREADY_REGISTER     EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_ALREADY_REGISTER)
#define EI_ERR_MAI_VDEC_NO_VBBLK                      EI_MADP_DEF_ERR(EI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_VDEC_NO_VBBLK)

typedef  EI_VOID (*EI_MAI_VDEC_MSG_Callback)( EI_HANDLE hVdecHandle, EI_S32 s32MsgId, EI_VOID* pContent, EI_VOID* priv);

typedef enum _eVdecType
{
    E_VDEC_H264,
    E_VDEC_H265,
    E_VDEC_JPEG,
    /*add after this line*/

    E_VDEC_BUTT
}eVdecType;

typedef struct _EiVdecOutBufInfo
{
    EI_U32 u32BufCnt;
    EI_U32 u32BufSize;
}EiVdecOutBufInfo;

typedef enum _eVdecBufType
{
    E_Vdec_BUF_IN,
    E_Vdec_BUF_OUT,
    E_Vdec_BUF_ALL,
    E_Vdec_BUF_BUTT
}eVdecBufType;

typedef struct _EiVdecStreamInfo
{
    EI_VOID* pStreamData;
    EI_U32 u32DataLen;
    EI_U32 u32pts;
    EI_U32 u32dts;
    EI_VOID* priv;
    EI_BOOL bEndOfStream;
    EI_BOOL bEndOfFrame;
    EI_BOOL bFlushBuffer;
}EiVdecStreamInfo;

typedef struct _EiVdecFrameInfo
{
    EI_FRAME_DATA_S stFrameData;
    /*do not change*/
    EI_VOID* priv;
}EiVdecFrameInfo;

typedef struct _EiVdecMediaInfo
{
    EI_MADP_PAYLOAD_TYPE_E eType;
    /*for video or image*/
    EI_S32 s32Width;
    EI_S32 s32Height;
    /*for video*/
    EI_S32 s32Fps;
    VDEC_SCALE_S stVdecScale;
    EI_U32 u32UserDisFrameNum;
    void* priv;
}EiVdecMediaInfo;

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

#endif
